﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lilium.Linq
{
	public static class EnumerableExtensions
	{
		public static T FirstOrDefault<T>(this IEnumerable<T> source, T @default)
		{
			if (source == null) throw new ArgumentNullException("source");

			using (var enumetaror = source.GetEnumerator())
				if (enumetaror.MoveNext())
					return enumetaror.Current;
				else
					return @default;
		}

		public static IEnumerable<T> Prepend<T>(this IEnumerable<T> source, T item)
		{
			if (source == null) throw new ArgumentNullException("source");

			yield return item;
			foreach (var current in source)
				yield return current;
		}
	}
}